package pkg

import "fmt"

var errorMap = map[int]string{
	//init
	100: "path had been already init!",
	//gen config
	101: "legal conf-file not found",
	102: "conf lost the require params<%s>",
	103: "ding config <%s> not found! gen it first before run!",
	//run
	104: "ding config not found! run <init> cmd in current path first!",
	105: "nginx run raise error \n =>%s",
}

type DError struct {
	ErrCode int
	ErrMsg  string
}

func (err *DError) Error() string {
	return err.ErrMsg
}

func NewDError(code int, val ...string) *DError {
	if len(val) > 0 {
		return &DError{ErrCode: code, ErrMsg: fmt.Sprintf(errorMap[code], val)}
	}
	return &DError{ErrCode: code, ErrMsg: errorMap[code]}

}
